avoid an extra cargo invocation
authorJim McGrath <jimmc2@gmail.com>
Mon, 8 May 2017 17:57:29 +0000 (12:57 -0500)
committerJim McGrath <jimmc2@gmail.com>
Mon, 8 May 2017 17:57:29 +0000 (12:57 -0500)
src/cargo/ops/cargo_rustc/context.rs
src/cargo/util/rustc.rs

index 1310ae189f81e2c8753f5cf3883c20851d04a1d1..865d4bbc078b4f9b5d44afa1ad982dc1a0356d78 100644 (file)
@@ -196,11 +196,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
 
         let mut with_cfg = process.clone();
+        with_cfg.arg("--print=sysroot");
         with_cfg.arg("--print=cfg");
 
-        let mut has_cfg = true;
+        let mut has_cfg_and_sysroot = true;
         let output = with_cfg.exec_with_output().or_else(|_| {
-            has_cfg = false;
+            has_cfg_and_sysroot = false;
             process.exec_with_output()
         }).chain_error(|| {
             human(format!("failed to run `rustc` to learn about \
@@ -237,14 +238,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
         }
 
-        let cfg = if has_cfg {
-            Some(try!(lines.map(Cfg::from_str).collect()))
-        } else {
-            None
-        };
-
-        if let Some(ref sysroot) = self.config.rustc()?.sysroot {
-            let mut rustlib = sysroot.clone();
+        if has_cfg_and_sysroot {
+            let line = match lines.next() {
+                Some(line) => line,
+                None => bail!("output of --print=sysroot missing when learning about \
+                               target-specific information from rustc"),
+            };
+            let mut rustlib = PathBuf::from(line);
             if kind == Kind::Host {
                 if cfg!(windows) {
                     rustlib.push("bin");
@@ -259,6 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 rustlib.push("lib");
                 self.compilation.target_dylib_path = Some(rustlib);
             }
+        }
+
+        let cfg = if has_cfg_and_sysroot {
+            Some(try!(lines.map(Cfg::from_str).collect()))
+        } else {
+            None
         };
 
         let info = match kind {
index cd2c55104306ad93ee170e45d0c903c887126a04..d401452d712fee08f0da58cfd4600f3d9387569b 100644 (file)
@@ -7,7 +7,6 @@ pub struct Rustc {
     pub wrapper: Option<PathBuf>,
     pub verbose_version: String,
     pub host: String,
-    pub sysroot: Option<PathBuf>,
 }
 
 impl Rustc {
@@ -36,20 +35,11 @@ impl Rustc {
             triple.to_string()
         };
 
-        let sysroot = {
-            let mut cmd = util::process(&path);
-            cmd.arg("--print=sysroot");      
-            cmd.exec_with_output().ok()
-                .and_then(|output| String::from_utf8(output.stdout).ok() )
-                .map(|s| PathBuf::from(s.trim()))
-        };
-
         Ok(Rustc {
             path: path,
             wrapper: wrapper,
             verbose_version: verbose_version,
             host: host,
-            sysroot: sysroot
         })
     }